#define DEBUG
#include <cstdio>

using namespace std;

int read(int p) {
  char c=getchar();
  for (; c<'0' || c>'9'; c=getchar());
  int ret=0;
  for (; c>='0' && c<='9'; c=getchar()) {
    if (p==3) ret = (ret+c-'0')%p;
    else ret = (c-'0')%p;
  }
  return ret;
}

int main() {
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);

  int t;
  scanf("%d", &t);
  for (int i=1; i<=t; i++) {
    int a=read(2), b=read(3), c=read(2), d=read(3);
    printf("%d\n", (int)(a+c)%2!=(b+d)%3);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
